import { PokerHand, isContinuous } from "./PokerHand.js";
import { PokerCard } from "../PokerCard.js";
export type { PokerCard, PokerType } from "../PokerCard.js";

/** 单顺 */
export class StraightPokerHand extends PokerHand {
  public value: number;
  constructor(cards: PokerCard[]) {
    super(cards);
    this.value = this.cards[0].value;
  }

  /**
   * 判断是否为单顺：五张或更多的连续单牌（如： 45678 或 78910JQK ）。不包括 2 点和双王。
   * @param cards 手牌
   * @returns
   */
  public static isStandard(cards: PokerCard[]) {
    // 少于5张牌
    if (cards.length < 5) {
      return false;
    }
    // 含有2或者双王
    if (cards.some((card) => card.value > 12)) {
      return false;
    }

    const nums = cards.map((card) => card.value);
    return isContinuous(nums, 1);
  }
  public isStandard = StraightPokerHand.isStandard;
  public isBetter(target: PokerHand): boolean {
    if (target instanceof StraightPokerHand && target.cards.length === this.cards.length) {
      return this.value > target.value;
    }

    return false;
  }
}

export default StraightPokerHand;
